import bp
import struct

if __name__ == '__main__':
    nn = bp.BPNeuralNetwork()
    with open("/sdcard/Git/pybp/mnist/train-images-idx3-ubyte","rb") as trif :
      trib = trif.read()
    mn,co,row,col = struct.unpack("!4I",trib[0:16])
    print(mn,co,row,col)
    images = []
    for i in range(1,co+1) :
      im = struct.unpack("!784B",trib[16+(i-1)*784:16+i*784])
      images.append(im)
    print(len(images))
    for i in range(0,29) :
      for j in range(0,29) :
        print(images[7][j*i-1])
    cases = [
      [0, 0, 0, 0],
      [0, 1, 1, 0],
      [1, 1, 0, 0],
      [0, 0, 1, 1],
    ]
    labels = [[0,0], [1,1], [1,0], [0,1]]
    nn.setup(4, 7, 2)
    nn.train(cases, labels, 10000, 0.05, 0.1)
    for case in cases:
      print(nn.predict(case))
